package com.ktgj.flight.controller;

import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.flight.common.hangbanguanjia.HangBanGuanJia;
import com.ktgj.flight.common.linkstar.LinkStar;
import com.ktgj.flight.common.pay._HuiFu;
import com.ktgj.flight.common.pay._Yeepay;
import com.ktgj.flight.common.spring._Spring;
import com.ktgj.flight.domain.InterfaceEntity.*;
import com.ktgj.flight.service.impl.TicketProducter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.jms.Queue;
import java.math.BigDecimal;


@ControllerAdvice
@RestController
@RequestMapping("/test")
public class TestController {

    private static final Logger log = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private TicketProducter ticketProducter;

    @Autowired
    private HangBanGuanJia hangBanGuanJia;

    @Autowired
    private _HuiFu huiFu;

    @Autowired
    private _Yeepay yeepay;

    @Autowired
    private LinkStar linkStar;

    @Autowired
    private _Spring spring;

    @RequestMapping("flightSearch")
    public AjaxResult flightSearch(@RequestBody MoFlightSearchRequest request) throws Exception {
        return AjaxResult.success(spring._FlightSearch(request));
    }

    @RequestMapping("getToken")
    public String getToken() {
        return hangBanGuanJia.getToken();
    }

    //查询航班信息
    @RequestMapping("getFlight")
    public AjaxResult getFlight(@RequestBody MoFlightSearchRequest moRequest) {
        return AjaxResult.success(hangBanGuanJia.flightSearch(moRequest));
    }

    //验舱验价
    @RequestMapping("priceConfirm")
    public AjaxResult priceConfirm(@RequestBody MoFlightCheckRequest moRequest) {
        return AjaxResult.success(hangBanGuanJia.flightCheck(moRequest));
    }

    //提交订单
    @RequestMapping("orderSubmit")
    public AjaxResult orderSubmit(@RequestBody MoCreateOrderRequest request) {
        return AjaxResult.success(hangBanGuanJia.orderCreate(request));
    }

    //取消订单
    @RequestMapping("orderCancel")
    public AjaxResult orderCancel(@RequestBody MoCancelOrderRequest request) {
        return AjaxResult.success(hangBanGuanJia.cancelOrder(request));
    }

    //查询订单详情
    @RequestMapping("orderDetail")
    public AjaxResult orderDetail(@RequestBody MoQueryOrderRequest request) {
        return AjaxResult.success(hangBanGuanJia.queryOrderInfo(request));
    }

    //出票前确认
    @RequestMapping("orderConfirm")
    public AjaxResult orderConfirm(@RequestBody MoOrderCheckRequest request) {
        return AjaxResult.success(hangBanGuanJia.orderCheck(request));
    }

    //提交出票(改期)
    @RequestMapping("orderIssue")
    public AjaxResult orderIssue(@RequestBody MoOrderPayRequest request) {
        return AjaxResult.success(hangBanGuanJia.orderPay(request));
    }

    //提交退票申请
    @RequestMapping("orderRefund")
    public AjaxResult orderRefund(@RequestBody MoOrderRefundRequest request) {
        return AjaxResult.success(hangBanGuanJia.orderRefund(request));
    }

    //查询改期航班列表
    @RequestMapping("searchChange")
    public AjaxResult searchChange(@RequestBody MoRescheduleSearchRequest moRequest) {
        return AjaxResult.success(hangBanGuanJia.searchChangeDateFlightInfo(moRequest));
    }

    //改期前确认
    @RequestMapping("changeConfirm")
    public AjaxResult changeConfirm(@RequestBody MoChangeConfirmRequest  request) {
        return AjaxResult.success(hangBanGuanJia.changeConfirm(request));
    }

    //提交改期申请
    @RequestMapping("orderChange")
    public AjaxResult orderChange(@RequestBody MoOrderChangeRequest  request) {
        return AjaxResult.success(hangBanGuanJia.orderChange(request));
    }

    //上传退改证明材料
    @RequestMapping("attachUplod")
    public AjaxResult attachUplod(@RequestBody MultipartFile[] multipartFiles) {
        return AjaxResult.success(hangBanGuanJia.attachUplod(multipartFiles));
    }

    //提交退改证明材料
    @RequestMapping("addAttachment")
    public AjaxResult addAttachment(@RequestParam("multipartFiles") MultipartFile[] multipartFiles, @RequestParam("OrderId") String OrderId, @RequestParam("ApplyType") int ApplyType, @RequestParam("ApplyId") String ApplyId) {
        MoAttachmentRequest request = new MoAttachmentRequest();
        request.multipartFiles = multipartFiles;
        request.OrderId = OrderId;
        request.ApplyType = ApplyType;
        request.ApplyId = ApplyId;
        return AjaxResult.success(hangBanGuanJia.addAttachment(request));
    }


    @GetMapping("/AutoPayOutTicket")
    public void test(){
        MoAutoPayOutTicketRequest request = new MoAutoPayOutTicketRequest();
        request.AirCode="CA";
        request.BigPnr="MX1LMW";
        request.PayAmount=new BigDecimal("1290");
        request.Pnr="JY76BV";
        request.TicketAmount=new BigDecimal("1230");
        request.Tax=new BigDecimal("60");
        request.OrderID = "jsj01";
        MoContacts moContacts = new MoContacts();
        moContacts.ContactMobile = "17710180782";
        moContacts.ContactName = "金色世纪";
        request.MoContacts = moContacts;
        //MoAutoPayOutTickeResponse autoPayOutTickeResponse = yeepay._AutoPayOutTicket(request);
    }

   @GetMapping("/testHuiFuAutoPayOutTicket")
    public void testHuiFuAutoPayOutTicket(){
       log.info("我打印的数据");
        MoAutoPayOutTicketRequest request = new MoAutoPayOutTicketRequest();
        request.Pnr="HZ1RL8";
        request.BigPnr="MJC15G";
        request.PayAmount=new BigDecimal("1230");
        request.OrderID="jsj001";
        request.AirCode="CA";
        request.TicketAmount=new BigDecimal("1");
        request.Tax=new BigDecimal("1");
//        MoAutoPayOutTickeResponse autoPayOutTickeResponse = huiFu._AutoPayOutTicket(request);
    }


    @GetMapping("/testLinkStar")
    public AjaxResult testLinkStar(@RequestBody MoFlightSearchRequest moRequest){
        return AjaxResult.success(linkStar._FlightSearch(moRequest));
    }

    @RequestMapping("send")
    public void send(String name) {
        ticketProducter.sendMessage("TicketQueue", name);
    }

}
